<?php

namespace app\modules\v1\controllers;

use Yii;
use yii\rest\ActiveController;
use app\modules\v1\models\Log;
use app\modules\v1\models\Usermoneyrecord;
use app\modules\v1\models\Usertalkrecord;

class UserOrderController extends ActiveController
{
    public $modelClass = '';
    
    public function actions(){
        
        $actions = parent::actions();
        
        unset($actions['index'],$actions['create'],$actions['delete'],$actions['view'],$actions['update']);
        
    }
    
    public function actionView($id){
        
        $this->log('GET', json_encode(['OID' => $id]));
        
        $moneyModel = Usermoneyrecord::find()->where(['oid' => $id])->one();
        
        $talkModel = Usertalkrecord::find()->where(['oid' => $id])->one();
        
        return [$moneyModel, $talkModel];
        
    }
    
    protected function log($op,$data){
        
        $log = new Log();
        
        $log->attributes = ['operation' => $op,'class' => 'User-Order','requestData' => $data,'dateTime' => date('Y-m-d H:i:s'),'ip' => Yii::$app->request->userIP];
        
        if(!$log->save()){
            return $log->getFirstError();
        }
        
    }
    
}
